/*
 * $Id: CheckoutAsAction.java 488 2008-08-20 16:59:47Z rcleveng $
 * 
 * Copyright (c) 2001 Boris Pruessmann and others. All rights reserved. This
 * program and the accompanying materials are made available under the terms of
 * the Common Public License v0.5 which accompanies this distribution, and is
 * available at http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors: Boris Pruessmann - Initial implementation.
 */
package net.sourceforge.perforce.ui.action;

import net.sourceforge.perforce.ui.internal.Policy;

import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.swt.widgets.Display;

/**
 * @version $Revision: 488 $
 * @author <a href="mailto:bpruessmann@users.sourceforge.net">Boris
 *         Pruessmann</a>
 */
public class CheckoutAsAction extends CheckoutAction {
  // ---------------------------------------------------------------------------
  // Protected Methods

  @Override
  protected String getProjectName(String projectName) {
    IInputValidator inputValidator = new IInputValidator() {
      public String isValid(String newText) {
        return null;
      }
    };

    final InputDialog dialog = new InputDialog(null, Policy.bind("CheckoutAsAction.dialogTitle"), //$NON-NLS-1$
        Policy.bind("CheckoutAsAction.dialogMessage"), //$NON-NLS-1$
        projectName, inputValidator);

    Display display = Display.getCurrent();
    if (display == null) {
      display = Display.getDefault();
    }

    final int[] result = new int[1];
    display.syncExec(new Runnable() {
      public void run() {
        result[0] = dialog.open();
      }
    });

    if (result[0] == InputDialog.OK) {
      return dialog.getValue();
    } else {
      return null;
    }
  }
}
